package cn.kgc.mes.type.controller;

import java.util.List;

import cn.kgc.mes.type.domain.MdItem;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.kgc.mes.common.annotation.Log;
import cn.kgc.mes.common.core.controller.BaseController;
import cn.kgc.mes.common.core.domain.AjaxResult;
import cn.kgc.mes.common.enums.BusinessType;
import cn.kgc.mes.type.domain.ItemType;
import cn.kgc.mes.type.service.IItemTypeService;
import cn.kgc.mes.common.utils.poi.ExcelUtil;

/**
 * 物料分类Controller
 * 
 * @author ydw
 * @date 2025-09-11
 */
@RestController
@RequestMapping("/type/type")
public class ItemTypeController extends BaseController
{
    @Autowired
    private IItemTypeService itemTypeService;

    /**
     * 查询物料分类列表
     */
//    @PreAuthorize("@ss.hasPermi('type:type:list')")
    @GetMapping("/list")
    public AjaxResult list(ItemType itemType){
        List<ItemType> list = itemTypeService.selectItemTypeList(itemType);
        return success(list);
    }

    /**
     * 导出物料分类列表
     */
//    @PreAuthorize("@ss.hasPermi('type:type:export')")
    @Log(title = "物料分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItemType itemType)
    {
        List<ItemType> list = itemTypeService.selectItemTypeList(itemType);
        ExcelUtil<ItemType> util = new ExcelUtil<ItemType>(ItemType.class);
        util.exportExcel(response, list, "物料分类数据");
    }

    /**
     * 获取物料分类详细信息
     */
//    @PreAuthorize("@ss.hasPermi('type:type:query')")
    @GetMapping(value = "/{itemTypeId}")
    public AjaxResult getInfo(@PathVariable("itemTypeId") Long itemTypeId)
    {
        return success(itemTypeService.selectItemTypeByItemTypeId(itemTypeId));
    }

    /**
     * 新增物料分类
     */
//    @PreAuthorize("@ss.hasPermi('type:type:add')")
    @Log(title = "物料分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItemType itemType)
    {
        return toAjax(itemTypeService.insertItemType(itemType));
    }

    /**
     * 修改物料分类
     */
//    @PreAuthorize("@ss.hasPermi('type:type:edit')")
    @Log(title = "物料分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItemType itemType)
    {
        return toAjax(itemTypeService.updateItemType(itemType));
    }

    /**
     * 删除物料分类
     */
//    @PreAuthorize("@ss.hasPermi('type:type:remove')")
    @Log(title = "物料分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemTypeIds}")
    public AjaxResult remove(@PathVariable Long[] itemTypeIds)
    {
        return toAjax(itemTypeService.deleteItemTypeByItemTypeIds(itemTypeIds));
    }
}
